﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;
using Antu.Core.DataAccess;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZJ_YHHZControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            if (!base.Page.IsPostBack)
            {
                BindData();
            }
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            CustomGridView1.OnLoadData += new EventHandler(CustomGridView1_OnLoadData);
            Button button1 = (Button)FindControl("button1");
            button1.Click += new EventHandler(button1_Click);
        }

        protected void button1_Click(object sender, EventArgs e)
        {
            BindData();
        }
        private void BindData()
        {
            CustomGridView CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
            CustomGridView1.RowDataBound += new GridViewRowEventHandler(CustomGridView1_RowDataBound);
            DataTable dt = _EluZSDataProvider.GetZJYH(GetStrWhere());
            CustomGridView1.DataSource = dt;
            CustomGridView1.RecordCount = dt.Rows.Count;
            CustomGridView1.DataBind();
        }

        protected void CustomGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow) {
                string tt = e.Row.Cells[3].Text.Trim();
                if (!string.IsNullOrEmpty(tt) || tt != "&nbsp;") {
                    string t1 = _EluZSDataProvider.GetSomeStr("ZS_BCBASICINFO", "sum(到账金额)", "开户银行", tt);
                    string t2 = _EluZSDataProvider.GetSomeStr("ZS_BCBASICINFO", "sum(划转金额)", "开户银行", tt);
                    e.Row.Cells[4].Text = t1;
                    e.Row.Cells[5].Text = t2;
                    string t4 = _EluZSDataProvider.GetYHProNum(tt);
                    e.Row.Cells[6].Text = t4;
                    e.Row.Cells[6].Attributes.Add("style", "cursor:pointer;color:blue;");
                    e.Row.Cells[6].Attributes.Add("onclick", "javascript:window.location.href=('../ZSManage/ProjectList.aspx?typeqs=" + tt + "');");
                }
            }
        }
        protected void CustomGridView1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }
        protected string GetStrWhere() {
            MPCalendar tDate1 = (MPCalendar)FindControl("tDate1");
            MPCalendar tDate2 = (MPCalendar)FindControl("tDate2");
            TextBox txt开户银行 = (TextBox)FindControl("txt开户银行");
            DropDownList ddl报结情况 = (DropDownList)FindControl("ddl报结情况");
            string strWhere = string.Empty;
            if (!string.IsNullOrEmpty(tDate1.Text)) { strWhere += " and 时间>= to_date('" + tDate1.Text + "','yyyy-mm-dd')"; }
            if (!string.IsNullOrEmpty(tDate2.Text)) { strWhere += " and 时间< to_date('" + tDate2.Text + "','yyyy-mm-dd')"; }
            if (!string.IsNullOrEmpty(txt开户银行.Text)) { strWhere += " and 开户银行 like '%" + txt开户银行.Text + "%'"; }
            if (!string.IsNullOrEmpty(ddl报结情况.SelectedValue)) { strWhere += " and 报结情况 = '" + ddl报结情况.SelectedValue + "'"; }
            return strWhere;
        }
    }
}


